package com.hfjyz.registration.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import com.hfjyz.registration.command.DepartEditCommand;

public class DepartEditValidator implements Validator {

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public boolean supports(Class clazz) {
		return clazz.isAssignableFrom(DepartEditCommand.class);
	}

	public void validate(Object target, Errors errors) {
		validateRoomInfo(target, errors);
	}

	private void validateRoomInfo(Object target, Errors errors) {
		DepartEditCommand v = (DepartEditCommand) target;
		if (v.getName() == null || v.getName().length() == 0) {
			errors.rejectValue("name", "required.name", "名称必须填写!");
		}
		if (v.getExamId() == null || v.getExamId() == -1) {
			errors.rejectValue("examId", "required.examId", "公告必须选择!");
		}

	}

}
